package algorithm;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import bean.Sports_record;

public class Personal_sportscredit_ranking {
	
	//返回函数，返回map<String,Integer>类型
	public Map<String,Object> Get_Ranking(List<Sports_record> list,String useraccount){ 
		Map<String,Object> outputmap = new HashMap<String,Object>();
		int accountnumber = -1;
		
		for(int i =0;i < list.size();i++){
			if(list.get(i).getUser_account().equals(useraccount)){
				accountnumber = i;
				break;
			}
		}
		outputmap.put("basketball",personal_basketball_Ranking(list,accountnumber));
		outputmap.put("basketball_record", list.get(accountnumber).getBasketball_record());
		outputmap.put("swimming", personal_swimming_Ranking(list,accountnumber));
		outputmap.put("swimming_record", list.get(accountnumber).getSwimming_record());
		outputmap.put("running", personal_running_Ranking(list,accountnumber));
		outputmap.put("running_record", list.get(accountnumber).getRunning_record());
		return outputmap;    //返回map类型，其中第二个数值是int类型
	}	
	
	
	//返回int类型，表示查询人的排名
	private int personal_basketball_Ranking(List<Sports_record> list,int pointnumber){
		double basketball_ranking = list.get(pointnumber).getBasketball_record();
		int ranking = 1;
		for(int i = 0;i < list.size();i++){
			if(basketball_ranking < list.get(i).getBasketball_record()){
				ranking++;
			}
		}
		return ranking;
	}
	
	private int personal_swimming_Ranking(List<Sports_record> list,int pointnumber){
		double swimming_ranking = list.get(pointnumber).getSwimming_record();
		int ranking = 1;
		for(int i = 0;i < list.size();i++){
			if(swimming_ranking < list.get(i).getSwimming_record()){
				ranking++;
			}
		}
		return ranking;
	}
	
	private int personal_running_Ranking(List<Sports_record> list,int pointnumber){
		double running_ranking = list.get(pointnumber).getRunning_record();
		int ranking = 1;
		for(int i = 0;i < list.size();i++){
			if(running_ranking < list.get(i).getRunning_record()){
				ranking++;
			}
		}
		return ranking;
	}
}
